import SwiftUI
import SPGlassKit

public struct GlassStepperExample: GlassExample {
    public static let componentID = "glass-stepper"
    @State private var guests = 2
    @State private var dose = 0.5
    @State private var zoom = 1.0
    @State private var fixed = 3

    public init() {}

    public var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 20) {
                GlassStepper("Guests", value: $guests, in: 1...12)

                GlassStepper("Dose", value: $dose, in: 0...2.5, step: 0.25) { value in
                    Measurement(value: value, unit: UnitMass.milligrams)
                        .formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number.precision(.fractionLength(2))))
                }

                // The upper bound 4 is not on a step from 0.5 by 0.75: the last press stops at the bound.
                GlassStepper("Zoom", value: $zoom, in: 0.5...4, step: 0.75) { value in
                    value.formatted(.percent.precision(.fractionLength(0)))
                }

                GlassStepper("Seats (fixed by your plan)", value: $fixed, in: 1...5)
                    .disabled(true)
            }
            .padding()
        }
    }
}

#Preview("GlassStepper") { GlassStepperExample().glassTheme(.crystal) }
